/********************************************************************
	Rhapsody	: 7.5 
	Login		: KBE
	Component	: DefaultComponent 
	Configuration 	: CodeConfig
	Model Element	: AlarmEvent
//!	Generated Date	: Wed, 19, Sep 2012  
	File Path	: DefaultComponent\CodeConfig\AlarmEvent.cpp
*********************************************************************/

//## auto_generated
#include "AlarmEvent.h"
//## auto_generated
#include "Reactor.h"
//## package Default

//## class AlarmEvent
AlarmEvent::AlarmEvent(Reactor* reactor, HANDLE h) {
    //#[ operation AlarmEvent(Reactor*,HANDLE)
    handle = h;
    itsReactor = reactor;
    strcpy(buffer_, "empty");
    //#]
}

AlarmEvent::AlarmEvent() {
}

AlarmEvent::AlarmEvent(Reactor * reactor, SOCK_Stream * stream) : peer_stream_(stream)  {
    //#[ operation AlarmEvent(Reactor *,SOCK_Stream *)
    //#[ operation LogEvent(Reactor*,SOCK_Stream)
    handle = (HANDLE)stream->get_handle();
    itsReactor = reactor;
    itsReactor->registerHandler(*this, READ_EVENT);
    //#]
}

AlarmEvent::~AlarmEvent() {
}

void AlarmEvent::handleEvent(HANDLE h, Event_Type& et) {
    //#[ operation handleEvent(HANDLE,Event_Type)
    if (et == type) {
    	int n = peer_stream_->recv_n(buffer_, sizeof(buffer_), 0);
    	if (n > 0) { 
    		AlarmAction();
    	}
    	else 
    	{
    		itsReactor->removeHandler(*this, type);
    		delete this; // Deallocate ourselves
    	}
    }
    //#]
}

void AlarmEvent::AlarmAction() {
    //#[ operation AlarmAction()
    printf("Alarm: %s\n", buffer_);
    //#]
}

char AlarmEvent::getBuffer_(int i1) const {
    return buffer_[i1];
}

void AlarmEvent::setBuffer_(int i1, char p_buffer_) {
    buffer_[i1] = p_buffer_;
}

SOCK_Stream * AlarmEvent::getPeer_stream_() const {
    return peer_stream_;
}

void AlarmEvent::setPeer_stream_(SOCK_Stream * p_peer_stream_) {
    peer_stream_ = p_peer_stream_;
}

/*********************************************************************
	File Path	: DefaultComponent\CodeConfig\AlarmEvent.cpp
*********************************************************************/
